window.addEventListener('load', function() {
    let topad = document.querySelector('.topad');
    let close_ad = topad.querySelector('.close_ad')
    close_ad.addEventListener('click', function() {
        topad.style.display = 'none';
    })

    // 头部个人信息模块 
    let user = document.querySelector('.user');
    let location = user.querySelector('.location');

    let js_menu = document.querySelector('.js_menu');
    let loca = js_menu.querySelector('.loca');
    location.addEventListener('mouseover', function() {
        this.style.backgroundColor = '#fff';
        loca.style.display = 'block';
        loca.style.backgroundColor = '#fff';

    });
    location.addEventListener('mouseout', function() {
        this.style.backgroundColor = '';
        loca.style.display = 'none';
        loca.style.backgroundColor = '';

    })
    let user_items = user.querySelector('.user_items');
    let my_jds = user_items.querySelector('.my_jds');
    let myjd = js_menu.querySelector('.myjd');
    my_jds.addEventListener('mouseover', function() {
        this.style.backgroundColor = '#fff';
        myjd.style.backgroundColor = '#fff';
        myjd.style.display = 'block';
    })
    my_jds.addEventListener('mouseout', function() {
        this.style.backgroundColor = '';
        myjd.style.backgroundColor = '';
        myjd.style.display = 'none';
    })

    //企业模块
    let my_qiye = user_items.querySelector('.my_qiye');
    let qiye = js_menu.querySelector('.qiye');
    my_qiye.addEventListener('mouseover', function() {
        this.style.backgroundColor = '#fff';
        qiye.style.backgroundColor = '#fff';
        qiye.style.display = 'block';
    })
    my_qiye.addEventListener('mouseout', function() {
            this.style.backgroundColor = '';
            qiye.style.backgroundColor = '';
            qiye.style.display = 'none';
        })
        // 手机京东
    let jd_mobile = user_items.querySelector('.jd_mobile');
    let jd_phone = js_menu.querySelector('.jd_phone');
    jd_mobile.addEventListener('mouseover', function() {
        this.style.backgroundColor = '#fff';
        jd_phone.style.backgroundColor = '#fff';
        jd_phone.style.display = 'block';
    })
    jd_mobile.addEventListener('mouseout', function() {
        this.style.backgroundColor = '';
        jd_phone.style.backgroundColor = '';
        jd_phone.style.display = 'none';
    });

    // 右侧轮播图
    let focus = document.querySelector('.right_lunbotu');
    let btn_l = focus.querySelector('.btn_l');
    let btn_r = focus.querySelector('.btn_r');
    let focusWidth = focus.offsetWidth;
    focus.addEventListener('mouseenter', function() {
        btn_l.style.display = 'block';
        btn_r.style.display = 'block';
        clearInterval(timer);
        timer = null; // 清除定时器变量
    });
    focus.addEventListener('mouseleave', function() {
        btn_l.style.display = 'none';
        btn_r.style.display = 'none';
        timer = setInterval(function() {
            //手动调用点击事件
            btn_r.click();
        }, 2000);
    });
    let right_content1 = focus.querySelector('.right_content1');
    let col_lis = right_content1.querySelectorAll('.col');
    let first = right_content1.children[0].cloneNode(true);
    right_content1.appendChild(first);
    var num = 0;
    // flag 节流阀
    var flag = true;
    btn_r.addEventListener('click', function() {
        if (flag) {
            flag = false; // 关闭节流阀
            // 如果走到了最后复制的一张图片，此时 我们的ul 要快速复原 left 改为 0
            if (num == right_content1.children.length - 1) {
                right_content1.style.left = 0;
                num = 0;
            }
            num++;
            animate(right_content1, -num * focusWidth, function() {
                flag = true; // 打开节流阀
            });
        }
    });
    btn_l.addEventListener('click', function() {
        if (flag) {
            flag = false;
            if (num == 0) {
                num = right_content1.children.length - 1;
                right_content1.style.left = -num * focusWidth + 'px';

            }
            num--;
            animate(right_content1, -num * focusWidth, function() {
                flag = true;
            });

        }
    });

    //京东秒杀轮播图
    let miaosha_lunbo = document.querySelector('.miaosha_lunbo');
    let ms_btn_l = miaosha_lunbo.querySelector('.btn_l');
    let ms_btn_r = miaosha_lunbo.querySelector('.btn_r');
    let miaosha_lunbo_Width = miaosha_lunbo.offsetWidth;

    let miaosha_content = miaosha_lunbo.querySelector('.miaosha_content');
    let ms_first = miaosha_content.children[0].cloneNode(true);
    miaosha_content.appendChild(ms_first);
    var num = 0;
    // flag 节流阀
    var flag = true;
    ms_btn_r.addEventListener('click', function() {
        if (flag) {
            flag = false; // 关闭节流阀
            // 如果走到了最后复制的一张图片，此时 我们的ul 要快速复原 left 改为 0
            if (num == miaosha_content.children.length - 1) {
                miaosha_content.style.left = 0;
                num = 0;
            }
            num++;
            animate(miaosha_content, -num * miaosha_lunbo_Width, function() {
                flag = true; // 打开节流阀
            });
        }
    });
    ms_btn_l.addEventListener('click', function() {
        if (flag) {
            flag = false;
            if (num == 0) {
                num = miaosha_content.children.length - 1;
                miaosha_content.style.left = -num * miaosha_lunbo_Width + 'px';

            }
            num--;
            animate(miaosha_content, -num * miaosha_lunbo_Width, function() {
                flag = true;
            });

        }
    });
})